import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;

public class TestColorChooser implements ChangeListener {
	private JFrame jf;
	private JLabel jl1,jl2,jl3;
	private JSlider js1,js2,js3;
	private JTextField jtf1,jtf2,jtf3;
	private JTextField jtf11,jtf22,jtf33;
	private JTextArea jta;
	
	public TestColorChooser() {
		jf=new JFrame();
		jl1=new JLabel("R:");
		jl2=new JLabel("G:");
		jl3=new JLabel("B:");
		js1=new JSlider(0,255,127);
		js2=new JSlider(0,255,127);
		js3=new JSlider(0,255,127);
		jtf1=new JTextField("127");
		jtf2=new JTextField("127");
		jtf3=new JTextField("127");
		jtf11=new JTextField(" "+Integer.toHexString(127)+" ");
		jtf22=new JTextField(" "+Integer.toHexString(127)+" ");
		jtf33=new JTextField(" "+Integer.toHexString(127)+" ");
		jta=new JTextArea(5,10);
		
		jtf1.setEditable(false);
		jtf2.setEditable(false);
		jtf3.setEditable(false);
		jtf11.setEditable(false);
		jtf22.setEditable(false);
		jtf33.setEditable(false);
		jta.setEditable(false);
		
		jta.setBackground(new Color(127,127,127));
		
	}
	
	public void init(){
		JPanel jp1=new JPanel();
		jp1.add(jl1);
		jp1.add(js1);
		jp1.add(jtf1);
		jp1.add(jtf11);
		jp1.add(jl2);
		jp1.add(js2);
		jp1.add(jtf2);
		jp1.add(jtf22);
		jp1.add(jl3);
		jp1.add(js3);
		jp1.add(jtf3);
		jp1.add(jtf33);
		
		JPanel jp2=new JPanel();
		jp2.add(jta);
		
		jf.add(jp1);
		jf.add(jp2,BorderLayout.EAST);
	}
	
	public void addEventHandler() {
		js1.addChangeListener(this);
		js2.addChangeListener(this);
		js3.addChangeListener(this);
	}
	
	public void showMe(){
		init();
		addEventHandler();
		jf.setSize(420,180);
		jf.setVisible(true);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public static void main(String[] args) {
		new TestColorChooser().showMe();
	}

	public void stateChanged(ChangeEvent e) {
		
		int r=js1.getValue();
		int g=js2.getValue();
		int b=js3.getValue();
		
		jtf1.setText(r+"");
		jtf2.setText(g+"");
		jtf3.setText(b+"");
		jtf11.setText(" "+Integer.toHexString(r)+" ");
		jtf22.setText(" "+Integer.toHexString(g)+" ");
		jtf33.setText(" "+Integer.toHexString(b)+" ");
		
		jta.setBackground(new Color(r,g,b));
		
		
		
	}
	
	
	
}
